/*
 * stack.c
 *
 * Version 1.0
 * Author: rtp
 *
 * Description: stack implementation
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include "stack.h"

stack s_create()
{
	stack ret = (stack)malloc(sizeof(s_cell));
	ret->content = 0;
	ret->next = NULL;

	return ret;
}

void s_push(stack* aStack, int content)
{
	stack ret = (stack)malloc(sizeof(s_cell));
	stack tmp = *aStack;

	ret->content = content;
	ret->next = tmp;
	ret->st_content = "";

	*aStack = ret;
}

void s_push_st(stack* aStack, char* content)
{
	stack ret = (stack)malloc(sizeof(s_cell));
	stack tmp = *aStack;

	ret->content = 0;
	ret->next = tmp;
	ret->st_content = content;

	*aStack = ret;
}

char* s_pop_st(stack* aStack)
{
	char* ret = (*aStack)->st_content;
	stack tmp = *aStack;

	if((*aStack)->next != NULL)
		*aStack = (*aStack)->next;

	free(tmp);

	return ret;
}

int s_pop(stack* aStack)
{
	int ret = (*aStack)->content;
	stack tmp = *aStack;

	if((*aStack)->next != NULL)
		*aStack = (*aStack)->next;

	free(tmp);

	return ret;
}

int s_empty(stack* aStack)
{
	if((*aStack)->next == NULL)
		return 1;
	return 0;
}
